// pages/teacher/student-detail/student-detail.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    studentInfo: {},
    loading: true,
    currentTab: 0, // 0: 基本信息, 1: 学习进度, 2: 缴费记录
    courseProgress: [],
    paymentRecords: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const studentId = options.studentId;
    if (studentId) {
      this.loadStudentDetail(studentId);
    }
  },

  /**
   * 加载学生详情
   */
  loadStudentDetail(studentId) {
    wx.showLoading({
      title: '加载中...'
    });

    // 模拟学生数据
    const studentInfo = {
      id: studentId,
      name: '张三',
      studentId: '2023001',
      class: '计算机科学与技术1班',
      avatar: '/images/avatar1.png',
      phone: '138****8888',
      email: 'zhangsan@example.com',
      paymentStatus: 'paid',
      totalAmount: 7380.00,
      paidAmount: 7380.00,
      unpaidAmount: 0,
      enrollmentDate: '2023-09-01',
      lastLoginTime: '2024-01-15 14:30'
    };

    const courseProgress = [
      {
        id: 1,
        title: '数据结构与算法',
        progress: 75,
        totalVideos: 20,
        watchedVideos: 15,
        status: 'learning'
      },
      {
        id: 2,
        title: 'Web前端开发',
        progress: 30,
        totalVideos: 18,
        watchedVideos: 5,
        status: 'learning'
      },
      {
        id: 3,
        title: '数据库原理',
        progress: 100,
        totalVideos: 15,
        watchedVideos: 15,
        status: 'completed'
      }
    ];

    const paymentRecords = [
      {
        id: 1,
        title: '2024年春季学期学费',
        amount: 5800.00,
        paymentDate: '2024-01-15',
        status: 'success'
      },
      {
        id: 2,
        title: '住宿费',
        amount: 1200.00,
        paymentDate: '2024-01-15',
        status: 'success'
      },
      {
        id: 3,
        title: '教材费',
        amount: 380.00,
        paymentDate: '2024-01-10',
        status: 'success'
      }
    ];

    setTimeout(() => {
      this.setData({
        studentInfo,
        courseProgress,
        paymentRecords,
        loading: false
      });
      wx.hideLoading();
    }, 1000);
  },

  /**
   * 切换标签页
   */
  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    this.setData({
      currentTab: parseInt(tab)
    });
  },

  /**
   * 打电话给学生
   */
  callStudent() {
    wx.makePhoneCall({
      phoneNumber: '13888888888'
    });
  },

  /**
   * 发送消息给学生
   */
  sendMessage() {
    wx.showToast({
      title: '消息功能开发中',
      icon: 'none'
    });
  }
})